<?php
require_once('init.php');
require_once('models/wallet.php');
/* TABLICA DO STWORZENIA: (!!!)
CREATE TABLE `wallet` (
  `id` int(11) NOT NULL auto_increment,
  `info` varchar(255) default NULL,
  `amount` decimal(5,2) default NULL,
  `added_date` int(11) default NULL,
  `added_ip` varchar(15) default NULL,
  PRIMARY KEY  (`id`)
);
*/

if (Auth::isAdmin()) {
	// obsluga dodawania z formularza dla zalogowanych uzytkownikow
	if (isset($_POST['submit'])) {
		$info = trim($_POST['info']);
		$amount = trim(str_replace(',','.',$_POST['amount']));
		$new_item = new Wallet();
		$new_item->setAmount($amount);
		$new_item->setInfo($info);
		$new_item->save();
		unset ($new_item);
	}
}
?>
<?php require_once('init.php'); ?>
<!DOCTYPE html>
<html>
<head>
<title>Silesia Racing Time Battle</title>
<!--[if IE]><script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script><![endif]-->
 <meta http-equiv="content-type" content="text/html; charset=utf-8">
<link rel="stylesheet" type="text/css" href="css/style.css" />
<link rel="stylesheet" type="text/css" href="table_sorter/style_blue.css" />
<script type="text/javascript" src="js/jquery-1.3.1.min.js"></script>  
<script type="text/javascript" src="js/jquery.betterTooltip.js"></script>  
<script type="text/javascript" src="js/jquery-latest.js"></script> 
<script type="text/javascript" src="js/jquery.tablesorter.js"></script>
<script>
$(document).ready(function() 
    { 
        $("#myTable").tablesorter(); 
    } 
); 

    
</script>
</head>
<body>
    <div id="wrapper">
        <div id="headerwrap">
        <div id="header">
           <p align="right"> Silesia Racing Time Battle EVOLution</p>
        </div>
        </div>
		<div id="topwrap">
        <div id="top_home">		
           <h2>Time Battle - Wallet</h2>
        </div>
        </div>
        <div id="leftcolumnwrap">
        <div id="leftcolumn">
            <?php include_once ('menu_left.php');?>
        </div>
        </div>
        <div id="contentwrap">
        <div id="content">
		<div>   
		<p></p>

<table id="table-2">
<tr>
	<th>Data wpisu</th>
	<th>Skąd / na co</th>
	<th>Kwota</th>
</tr>
<?php
$wallet_items = WalletDAO::getAll();
foreach ($wallet_items as $wallet) {
	echo '<tr>';
	echo '<td>' . $wallet->getAddedDate() . '</td>';
	echo '<td>' . $wallet->getInfo() . '</td>';
	echo '<td>' . $wallet->getAmount() . '</td>';
	echo '</tr>';
}
unset ($wallet_items);
echo '<tr><td>&nbsp;</td><td style="text-align: right;">SUMA:</td><td>' . WalletDAO::getWalletSum() . '</td></tr>';
?>
</table>
<?php
if (Auth::isAdmin()) {
	// formularz dodawania nowego wpisu do portfela
	// tylko dla zalogowanych użytkowników
	echo <<<DUPA
<form action="finanse.php" method="post">
	<p style="text-weight: bold;">Dodaj wpis do portfela</p>
	<table>
	<TR>
	<TD>
	<p>Skąd / na co:
	</TD>
	<TD>
	 <input type="text" name="info" /></p>
	</TD>
	</TR>
	<TR>
	<TD>
	<p>Kwota: 
	</TD>
	<TD>
	<input type="text" name="amount" /></p>
	</TD>
	</TR>
	</TABLE>
	<p>jeżeli wydatek napisać z minusem, jeżeli zysk napisać po prostu kwotę</p>
	<p><input type="submit" name="submit" value="Dodaj" /></p>
</form>
DUPA;
}
?>
</div>
        </div>
        </div>
        <div id="rightcolumnwrap">
        <div id="rightcolumn">
			<?php include_once ('right_column.php');?>
			<p></p>
        </div>
        </div>
        <div id="footerwrap">
        <div id="footer">
            <p>Silesia Racing Time Battle</p>
        </div>
        </div>
    </div>
</body>
</html>
